extends Node2D

#
# 1. 物理元素的移动 move_and_slide
# 2. 碰撞检测，layer与mask
# 3. 碰撞检测区域 Area2D
#	回调中会返回碰撞的目标对象，可以获取其坐标用于追踪目标
#
#
# Vector2  ？
# 基础动画 ？
# 动画树   ？
# 
#
#
#
#
#
#
#

onready var child1 = $"KinematicBody2D"

var velocity = Vector2.ZERO
var click_vel = Vector2.ZERO

var Rain

func _init():
	Rain = load("res://Study/Rain.tscn")
	
	print("call _init")

# Called when the node enters the scene tree for the first time.
func _ready():
	randomize()
	print(Time.get_datetime_dict_from_system())
	print("call _ready")
	print(get_global_position())
	print(child1.get_global_position())
	
	
	
func _input(event):
	if event is InputEventMouseButton:
		if event.is_pressed():
			click_vel = event.position
		else:
			click_vel = Vector2.ZERO
	pass
	
	
func create_rain():
	var rdx = rand_range(10, 480)
	var rr = Rain.instance()
	rr.global_position.x = rdx
	rr.global_position.y = -20
	rr.speed = rand_range(1, 4)
	rr.fp = rand_range(1, 2)
	add_child(rr)

func _physics_process(delta):
	create_rain()
	#create_rain()
	
	var direct = Vector2.ZERO
	var cp1 = child1.get_global_position()
	
	
	
	direct.x = Input.get_action_strength("ui_right")-Input.get_action_strength("ui_left")
	direct.y = Input.get_action_strength("ui_down")-Input.get_action_strength("ui_up")
	direct = direct.normalized()
	
	if direct == Vector2.ZERO:
		velocity = velocity.move_toward(Vector2.ZERO, 10)
		child1.move_and_slide(velocity)
	else:
		velocity = velocity.move_toward(direct * 100, 10)
	
	child1.move_and_slide(velocity)
	
	pass

func _process(delta):
	
	#print("_process: ", delta)
	pass



